﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PcapDotNet.Core;
using System.Diagnostics;

namespace WNistnet
{
    public partial class Form1 : Form
    {
        Router router = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            router = new Router(null, null);


            IList<LivePacketDevice> allDevicePacket = Init.ListAllDevice();
            if (allDevicePacket != null)
            {
                router.AllDevices = allDevicePacket;
                for (int i = 0; i < allDevicePacket.Count; i++)
                {
                    this.cbxDevices.Items.Add(allDevicePacket[i].Description);
                }
                
            }
        }

        private void cbxDevices_SelectedIndexChanged(object sender, EventArgs e)
        {
            //LivePacketDevice selectedDevice = this.cbxDevices.sel
            if (null == router)
            {
                return;
            }
            for (int i = 0; i < this.router.AllDevices.Count; i++)
            {
                if (this.cbxDevices.SelectedItem.ToString().Equals(this.router.AllDevices[i].Description))
                {
                    string temp = null;
                    for (int j = 0; j < this.router.AllDevices[i].Addresses.Count; j++)
                    {
                        temp = this.router.AllDevices[i].Addresses[j].Address.ToString() + "\n";
                        this.lbIpOfDevice.Text += temp;
                    }
                    temp = null;
                }
            }
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            
            //获取各种配置参数


            //初始化路由器，设置路由器运行状态
            //初始化ARP表
            Init.InitArpTable();

            //获取PC的CPU性能（可选）

            //启动工作线程
        }
    }
}
